cap n log close
cd "/export/projects2/wkerr_AHA_project/replication"
log using aha-analysis-2.log, replace

* Kerr, Kerr, and Smith, AHA
* Core Analysis
* stata-mp18 -b do aha-analysis-2.do
* Last Modified: June 2025

clear
set more off

ssc install estout, replace
ssc install b1x2, replace

******************************************************************************************
**Figure 1: Immigration from Vietnam to America

***A. Arrival dates of immigrants from Vietnam as present in 2015-2019 ACS

use vi yrimmig perwt byr regyr if regyr==2019 using ./temp/CoreData.dta, clear

keep if vi>0 & vi!=.

drop if yrimmig==.

qui replace yrimmig=1968 if yrimmig<=1970 & yrimmig!=0 & yrimmig !=996
label define yrimmig_lbl 1968 "1970 and before", modify

tab yrimmig [fw=perwt], plot

***B. Official count of Amerasian arrivals

*Data from US government documents

******************************************************************************************
**Figure 2: Language proficiency and education levels of young versus older AHA arrivals relative to all US natives

eststo clear

use if inlist(compgrp, 0, 1, 3, 4) using ./temp/CoreData.dta, clear
qui replace compgrp=2 if compgrp==3 | compgrp==4
qui drop if regyr==.
qui sort regyr
qui g long nobs=.
qui g b_young=.
qui g b_old=.
qui g se_young=.
qui g se_old=.
qui g low95_young=.
qui g high95_young=.
qui g low95_old=.
qui g high95_old=.

foreach Y in ewell yrseduc {

preserve

foreach z of num 1990 2000 2009 2014 2019 {
qui areg `Y' ib3.compgrp age gender if regyr==`z', absorb(statefip) vce(cluster statefip) allbaselevels
qui replace nobs=e(N) if regyr==`z'
matrix M = r(table)
qui replace b_young=M[1,1] if regyr==`z'
qui replace b_old=M[1,2] if regyr==`z'
qui replace se_young=M[2,1] if regyr==`z'
qui replace se_old=M[2,2] if regyr==`z'
qui replace low95_young=M[5,1] if regyr==`z'
qui replace high95_young=M[6,1] if regyr==`z'
qui replace low95_old=M[5,2] if regyr==`z'
qui replace high95_old=M[6,2] if regyr==`z'
}

by regyr, sort: gen byte counter=(_n==1)
keep if counter==1
qui gen maxi=high95_young
qui replace maxi=low95_young if low95_young>maxi
qui replace maxi=high95_old if high95_old>maxi
qui replace maxi=low95_old if low95_old>maxi
qui replace maxi=.01 if .01>maxi
qui egen maxval=max(maxi)

qui gen mini=high95_young
qui replace mini=low95_young if low95_young<mini
qui replace mini=high95_old if high95_old<mini
qui replace mini=low95_old if low95_old<mini
qui egen minval=min(mini)

local range = (maxval - minval)
local pad = 0.10*(`range')
local min_scale = min(round(minval - `pad', 0.1),-0.1)
local max_scale = max(round(maxval + `pad', 0.1),0.1)
local int_scale=round(((`max_scale' - `min_scale')/5), 0.05)
local max_scale = max(round(maxval + `pad', 0.1),0.1,(`min_scale'+(`int_scale'*5)))

twoway rcap low95_young high95_young regyr, title(`Y', ring(12)) ytitle(Regression coefficients) xtitle(Year) xlabel(1990 "1990 5pct" 2000 "2000 5pct" 2009 "2005-2009" 2014 "2010-2014" 2019 "2015-2019", labsize(small) nogrid) xmlabel(1990 "15-22 y.o." 2000 "25-32 y.o." 2009 "30-41 y.o." 2014 "35-46 y.o." 2019 "40-51 y.o.", labsize(vsmall) labgap(4)) msize(large) graphregion(margin(l+2 r+5)) graphregion(color(white)) bgcolor(white) yscale(range(`min_scale' `max_scale')) ylabel(`min_scale'(`int_scale')`max_scale', nogrid format(%9.2f) labsize(vsmall)) lcolor(green) legend(rows(1) order(2 "young AHA" 4 "older AHA") position(6) ring(3)) note("ages of young AHA group in each time period are included in text below x-axis") || scatter b_young regyr, connect(l) lpattern(dash) mcolor(green) lcolor(green) msize(medlarge) yline(0, lwidth(large) lcolor(dkgreen) lpattern(solid)) msymbol(diamond) || rcap low95_old high95_old regyr, msize(large) lcolor(midblue) || scatter b_old regyr, connect(l) lpattern(shortdash) mcolor(midblue) lcolor(midblue) msize(medlarge) msymbol(circle)
graph export ./output/figure2_`Y'.pdf, replace

restore
}

foreach Y in HSup colup {
	
preserve

foreach z of num 1990 2000 2009 2014 2019 {
qui areg `Y' ib3.compgrp age gender if regyr==`z', absorb(statefip) vce(cluster statefip) allbaselevels
qui replace nobs=e(N) if regyr==`z'
matrix M = r(table)
qui replace b_young=M[1,1] if regyr==`z'
qui replace b_old=M[1,2] if regyr==`z'
qui replace se_young=M[2,1] if regyr==`z'
qui replace se_old=M[2,2] if regyr==`z'
qui replace low95_young=M[5,1] if regyr==`z'
qui replace high95_young=M[6,1] if regyr==`z'
qui replace low95_old=M[5,2] if regyr==`z'
qui replace high95_old=M[6,2] if regyr==`z'

qui replace b_young=0 if regyr==1990
qui replace b_old=0 if regyr==1990
qui replace se_young=0 if regyr==1990
qui replace se_old=0 if regyr==1990
qui replace low95_young=0 if regyr==1990
qui replace high95_young=0 if regyr==1990
qui replace low95_old=0 if regyr==1990
qui replace high95_old=0 if regyr==1990
}
by regyr, sort: gen byte counter=(_n==1)
keep if counter==1
gen maxi=high95_young
qui replace maxi=low95_young if low95_young>maxi
qui replace maxi=high95_old if high95_old>maxi
qui replace maxi=low95_old if low95_old>maxi
egen maxval=max(maxi)

gen mini=high95_young
qui replace mini=low95_young if low95_young<mini
qui replace mini=high95_old if high95_old<mini
qui replace mini=low95_old if low95_old<mini
egen minval=min(mini)

local range = (maxval - minval)
local pad = 0.10*(`range')
local min_scale = -0.3
local max_scale = 0.1
local int_scale=round(((`max_scale' - `min_scale')/4), 0.05)

twoway rcap low95_young high95_young regyr, title(`Y', ring(12)) ytitle(Regression coefficients) xtitle(Year) xlabel(1990 "1990 5pct" 2000 "2000 5pct" 2009 "2005-2009" 2014 "2010-2014" 2019 "2015-2019", labsize(small) nogrid) xmlabel(1990 "15-22 y.o." 2000 "25-32 y.o." 2009 "30-41 y.o." 2014 "35-46 y.o." 2019 "40-51 y.o.", labsize(vsmall) labgap(4)) msize(large) graphregion(margin(l+2 r+5)) graphregion(color(white)) bgcolor(white) yscale(range(`min_scale' `max_scale')) ylabel(`min_scale'(`int_scale')`max_scale', nogrid format(%9.2f) labsize(vsmall)) lcolor(green) legend(rows(1) order(2 "young AHA" 4 "older AHA") position(6) ring(3)) note("ages of young AHA group in each time period are included in text below x-axis") || scatter b_young regyr, connect(l) lpattern(dash) mcolor(green) lcolor(green) msize(medlarge) yline(0, lwidth(large) lcolor(dkgreen) lpattern(solid)) msymbol(diamond) || rcap low95_old high95_old regyr, msize(large) lcolor(midblue) || scatter b_old regyr, connect(l) lpattern(shortdash) mcolor(midblue) lcolor(midblue) msize(medlarge) msymbol(circle)
graph export ./output/figure2_`Y'.pdf, replace

restore	
}

******************************************************************************************
**Figure 3: Extended analysis of language proficiency and education levels relative to white US natives

use if inlist(compgrp, 0, 1, 3, 4, 5) using ./temp/CoreData.dta, clear
drop if regyr==.
qui sort regyr
qui g long nobs=.
qui g b_young=.
qui g b_old=.
qui g b_minority=.
qui g b_cmpim=.
qui g se_young=.
qui g se_old=.
qui g se_minority=.
qui g se_cmpim=.
qui g low95_young=.
qui g high95_young=.
qui g low95_old=.
qui g high95_old=.
qui g low95_minority=.
qui g high95_minority=.
qui g low95_cmpim=.
qui g high95_cmpim=.

foreach Y in ewell yrseduc {

preserve

foreach z of num 1990 2000 2009 2014 2019 {
qui areg `Y' ib3.compgrp age gender if regyr==`z', absorb(statefip) vce(cluster statefip) allbaselevels
qui replace nobs=e(N) if regyr==`z'
matrix M = r(table)
qui replace b_young=M[1,1] if regyr==`z'
qui replace b_old=M[1,2] if regyr==`z'
qui replace b_minority=M[1,4] if regyr==`z'
qui replace b_cmpim=M[1,5] if regyr==`z'
qui replace se_young=M[2,1] if regyr==`z'
qui replace se_old=M[2,2] if regyr==`z'
qui replace se_minority=M[2,4] if regyr==`z'
qui replace se_cmpim=M[2,5] if regyr==`z'
qui replace low95_young=M[5,1] if regyr==`z'
qui replace high95_young=M[6,1] if regyr==`z'
qui replace low95_old=M[5,2] if regyr==`z'
qui replace high95_old=M[6,2] if regyr==`z'
qui replace low95_minority=M[5,4] if regyr==`z'
qui replace high95_minority=M[6,4] if regyr==`z'
qui replace low95_cmpim=M[5,5] if regyr==`z'
qui replace high95_cmpim=M[6,5] if regyr==`z'
}
by regyr, sort: gen byte counter=(_n==1)
keep if counter==1
gen maxi=high95_young
qui replace maxi=low95_young if low95_young>maxi
qui replace maxi=high95_old if high95_old>maxi
qui replace maxi=low95_old if low95_old>maxi
qui replace maxi=high95_minority if high95_minority>maxi
qui replace maxi=low95_minority if low95_minority>maxi
qui replace maxi=high95_cmpim if high95_cmpim>maxi
qui replace maxi=low95_cmpim if low95_cmpim>maxi
qui egen maxval=max(maxi)

gen mini=high95_young
qui replace mini=low95_young if low95_young<mini
qui replace mini=high95_old if high95_old<mini
qui replace mini=low95_old if low95_old<mini
qui replace mini=high95_minority if high95_minority<mini
qui replace mini=low95_minority if low95_minority<mini
qui replace mini=high95_cmpim if high95_cmpim<mini
qui replace mini=low95_cmpim if low95_cmpim<mini
qui egen minval=min(mini)

local max_scale=maxval
local min_scale=minval
local range = (maxval - minval)
local pad = 0.10*(`range')
local min_scale = round(minval - `pad', 0.1)
local max_scale = round(maxval + `pad', 0.1)
local int_scale=round(((`max_scale' - `min_scale')/5), 0.05)
local max_scale = max(round(maxval + `pad', 0.1),0.1,(`min_scale'+(`int_scale'*5)))

twoway rcap low95_young high95_young regyr, title(`Y', ring(12)) ytitle(Regression coefficients, margin(medium)) xtitle(Year, margin(medium)) xlabel(1990 "1990 5pct" 2000 "2000 5pct" 2009 "2005-2009" 2014 "2010-2014" 2019 "2015-2019", labsize(small) nogrid) xmlabel(1990 "15-22 y.o." 2000 "25-32 y.o." 2009 "30-41 y.o." 2014 "35-46 y.o." 2019 "40-51 y.o.", labsize(vsmall) labgap(4)) msize(large) graphregion(margin(l+2 r+5)) graphregion(color(white)) bgcolor(white) yscale(range(`min_scale' `max_scale')) ylabel(`min_scale'(`int_scale')`max_scale', nogrid format(%9.2f) labsize(vsmall)) lcolor(green) legend(rows(2) order(2 "young AHA" 4 "older AHA" 6 "US native minorities" 8 "non-Vietnamese immig.") size(vsmall) position(6) ring(3)) note("ages of young AHA group in each time period are included in text below x-axis") || scatter b_young regyr, connect(l) lpattern(dash) mcolor(green) lcolor(green) msize(medlarge) yline(0, lwidth(large) lcolor(dkgreen) lpattern(solid)) msymbol(diamond) || rcap low95_old high95_old regyr, msize(large) lcolor(midblue) || scatter b_old regyr, connect(l) lpattern(shortdash) mcolor(midblue) lcolor(midblue) msize(medlarge) msymbol(circle) || rcap low95_minority high95_minority regyr, lcolor(black) || scatter b_minority regyr, connect(l) lpattern(longdash_dot) mcolor(black) lcolor(black) msize(medlarge) msymbol(triangle) || rcap low95_cmpim high95_cmpim regyr, lcolor(orange) || scatter b_cmpim regyr, connect(l) lpattern(dash_dot) mcolor(orange) lcolor(orange) msize(medlarge) msymbol(smcircle)
graph export ./output/figure3_`Y'.pdf, replace

restore
}

foreach Y in HSup colup {
	
preserve

foreach z of num 1990 2000 2009 2014 2019 {
qui areg `Y' ib3.compgrp age gender if regyr==`z', absorb(statefip) vce(cluster statefip) allbaselevels
qui replace nobs=e(N) if regyr==`z'
matrix M = r(table)
qui replace b_young=M[1,1] if regyr==`z'
qui replace b_old=M[1,2] if regyr==`z'
qui replace b_minority=M[1,4] if regyr==`z'
qui replace b_cmpim=M[1,5] if regyr==`z'
qui replace se_young=M[2,1] if regyr==`z'
qui replace se_old=M[2,2] if regyr==`z'
qui replace se_minority=M[2,4] if regyr==`z'
qui replace se_cmpim=M[2,5] if regyr==`z'
qui replace low95_young=M[5,1] if regyr==`z'
qui replace high95_young=M[6,1] if regyr==`z'
qui replace low95_old=M[5,2] if regyr==`z'
qui replace high95_old=M[6,2] if regyr==`z'
qui replace low95_minority=M[5,4] if regyr==`z'
qui replace high95_minority=M[6,4] if regyr==`z'
qui replace low95_cmpim=M[5,5] if regyr==`z'
qui replace high95_cmpim=M[6,5] if regyr==`z'

qui replace b_young=0 if regyr==1990
qui replace b_old=0 if regyr==1990
qui replace b_minority=0 if regyr==1990
qui replace b_cmpim=0 if regyr==1990
qui replace se_young=0 if regyr==1990
qui replace se_old=0 if regyr==1990
qui replace se_minority=0 if regyr==1990
qui replace se_cmpim=0 if regyr==1990
qui replace low95_young=0 if regyr==1990
qui replace high95_young=0 if regyr==1990
qui replace low95_old=0 if regyr==1990
qui replace high95_old=0 if regyr==1990
qui replace low95_minority=0 if regyr==1990
qui replace high95_minority=0 if regyr==1990
qui replace low95_cmpim=0 if regyr==1990
qui replace high95_cmpim=0 if regyr==1990
}
by regyr, sort: gen byte counter=(_n==1)
keep if counter==1
qui gen maxi=high95_young
qui replace maxi=low95_young if low95_young>maxi
qui replace maxi=high95_old if high95_old>maxi
qui replace maxi=low95_old if low95_old>maxi
qui replace maxi=high95_minority if high95_minority>maxi
qui replace maxi=low95_minority if low95_minority>maxi
qui replace maxi=high95_cmpim if high95_cmpim>maxi
qui replace maxi=low95_cmpim if low95_cmpim>maxi
qui egen maxval=max(maxi)

qui gen mini=high95_young
qui replace mini=low95_young if low95_young<mini
qui replace mini=high95_old if high95_old<mini
qui replace mini=low95_old if low95_old<mini
qui replace mini=high95_minority if high95_minority<mini
qui replace mini=low95_minority if low95_minority<mini
qui replace mini=high95_cmpim if high95_cmpim<mini
qui replace mini=low95_cmpim if low95_cmpim<mini
qui egen minval=min(mini)

local max_scale=maxval
local min_scale=minval
local range = (maxval - minval)
local pad = 0.10*(`range')
local min_scale = -0.3
local max_scale = 0.1
local int_scale=round(((`max_scale' - `min_scale')/4), 0.05)

twoway rcap low95_young high95_young regyr, title(`Y', ring(12)) ytitle(Regression coefficients) xtitle(Year) xlabel(1990 "1990 5pct" 2000 "2000 5pct" 2009 "2005-2009" 2014 "2010-2014" 2019 "2015-2019", labsize(small) nogrid) xmlabel(1990 "15-22 y.o." 2000 "25-32 y.o." 2009 "30-41 y.o." 2014 "35-46 y.o." 2019 "40-51 y.o.", labsize(vsmall) labgap(4)) msize(large) graphregion(margin(l+2 r+5)) graphregion(color(white)) bgcolor(white) yscale(range(`min_scale' `max_scale')) ylabel(`min_scale'(`int_scale')`max_scale', nogrid format(%9.2f) labsize(vsmall)) lcolor(green) legend(rows(2) order(2 "young AHA" 4 "older AHA" 6 "US native minorities" 8 "non-Vietnamese immig.") size(vsmall) position(6) ring(3)) note("ages of young AHA group in each time period are included in text below x-axis") || scatter b_young regyr, connect(l) lpattern(dash) mcolor(green) lcolor(green) msize(medlarge) yline(0, lwidth(large) lcolor(dkgreen) lpattern(solid)) msymbol(diamond) || rcap low95_old high95_old regyr, msize(large) lcolor(midblue) || scatter b_old regyr, connect(l) lpattern(shortdash) mcolor(midblue) lcolor(midblue) msize(medlarge) msymbol(circle) || rcap low95_minority high95_minority regyr, lcolor(black) || scatter b_minority regyr, connect(l) lpattern(longdash_dot) mcolor(black) lcolor(black) msize(medlarge) msymbol(triangle) || rcap low95_cmpim high95_cmpim regyr, lcolor(orange) || scatter b_cmpim regyr, connect(l) lpattern(dash_dot) mcolor(orange) lcolor(orange) msize(medlarge) msymbol(smcircle)
graph export ./output/figure3_`Y'.pdf, replace

restore
}

******************************************************************************************
**Figure 4: Wages and income of young versus older AHA arrivals relative to all US natives

use if inlist(compgrp, 0, 1, 3, 4) using ./temp/CoreData.dta, clear
qui replace compgrp=2 if compgrp==3 | compgrp==4
drop if regyr==.
qui sort regyr
qui g long nobs=.
qui g b_young=.
qui g b_old=.
qui g se_young=.
qui g se_old=.
qui g low95_young=.
qui g high95_young=.
qui g low95_old=.
qui g high95_old=.

foreach Y in incwage inctot {
	
preserve

foreach z of num 1990 2000 2009 2014 2019 {
qui areg `Y' ib3.compgrp age gender if regyr==`z', absorb(statefip) vce(cluster statefip) allbaselevels
qui replace nobs=e(N) if regyr==`z'
matrix M = r(table)
qui replace b_young=M[1,1] if regyr==`z'
qui replace b_old=M[1,2] if regyr==`z'
qui replace se_young=M[2,1] if regyr==`z'
qui replace se_old=M[2,2] if regyr==`z'
qui replace low95_young=M[5,1] if regyr==`z'
qui replace high95_young=M[6,1] if regyr==`z'
qui replace low95_old=M[5,2] if regyr==`z'
qui replace high95_old=M[6,2] if regyr==`z'

qui replace b_young=0 if regyr==1990
qui replace b_old=0 if regyr==1990
qui replace se_young=0 if regyr==1990
qui replace se_old=0 if regyr==1990
qui replace low95_young=0 if regyr==1990
qui replace high95_young=0 if regyr==1990
qui replace low95_old=0 if regyr==1990
qui replace high95_old=0 if regyr==1990
}
by regyr, sort: gen byte counter=(_n==1)
keep if counter==1

qui gen maxi=high95_young
qui replace maxi=low95_young if low95_young>maxi
qui replace maxi=high95_old if high95_old>maxi
qui replace maxi=low95_old if low95_old>maxi
qui egen maxval=max(maxi)

qui gen mini=high95_young
qui replace mini=low95_young if low95_young<mini
qui replace mini=high95_old if high95_old<mini
qui replace mini=low95_old if low95_old<mini
qui egen minval=min(mini)

local max_scale=maxval
local min_scale=minval
local range = (maxval - minval)
local pad = 0.10*(`range')
local min_scale = round(minval - `pad', 0.1)
local max_scale = round(maxval + `pad', 0.1)
local int_scale=round(((`max_scale' - `min_scale')/5), 0.05)
local max_scale = max(round(maxval + `pad', 0.1),0.1,(`min_scale'+(`int_scale'*5)))


twoway rcap low95_young high95_young regyr, title(`Y', ring(12)) ytitle(Regression coefficients) xtitle(Year) xlabel(1990 "1990 5pct" 2000 "2000 5pct" 2009 "2005-2009" 2014 "2010-2014" 2019 "2015-2019", labsize(small) nogrid) xmlabel(1990 "15-22 y.o." 2000 "25-32 y.o." 2009 "30-41 y.o." 2014 "35-46 y.o." 2019 "40-51 y.o.", labsize(vsmall) labgap(4)) msize(large) graphregion(margin(l+2 r+5)) graphregion(color(white)) bgcolor(white) yscale(range(`min_scale' `max_scale')) ylabel(`min_scale'(`int_scale')`max_scale', nogrid format(%9.2f) labsize(vsmall)) lcolor(green) legend(rows(1) order(2 "young AHA" 4 "older AHA") position(6) ring(3)) note("ages of young AHA group in each time period are included in text below x-axis") || scatter b_young regyr, connect(l) lpattern(dash) mcolor(green) lcolor(green) msize(medlarge) yline(0, lwidth(large) lcolor(dkgreen) lpattern(solid)) msymbol(diamond) || rcap low95_old high95_old regyr, msize(large) lcolor(midblue) || scatter b_old regyr, connect(l) lpattern(shortdash) mcolor(midblue) lcolor(midblue) msize(medlarge) msymbol(circle)
graph export ./output/figure4_`Y'.pdf, replace	

restore
}


foreach Y in linincwg lininct {
	
preserve

foreach z of num 1990 2000 2009 2014 2019 {
qui areg `Y' ib3.compgrp age gender if regyr==`z', absorb(statefip) vce(cluster statefip) allbaselevels
qui replace nobs=e(N) if regyr==`z'
matrix M = r(table)
qui replace b_young=M[1,1] if regyr==`z'
qui replace b_old=M[1,2] if regyr==`z'
qui replace se_young=M[2,1] if regyr==`z'
qui replace se_old=M[2,2] if regyr==`z'
qui replace low95_young=M[5,1] if regyr==`z'
qui replace high95_young=M[6,1] if regyr==`z'
qui replace low95_old=M[5,2] if regyr==`z'
qui replace high95_old=M[6,2] if regyr==`z'

qui replace b_young=0 if regyr==1990
qui replace b_old=0 if regyr==1990
qui replace se_young=0 if regyr==1990
qui replace se_old=0 if regyr==1990
qui replace low95_young=0 if regyr==1990
qui replace high95_young=0 if regyr==1990
qui replace low95_old=0 if regyr==1990
qui replace high95_old=0 if regyr==1990
}
by regyr, sort: gen byte counter=(_n==1)
keep if counter==1

qui gen maxi=high95_young
qui replace maxi=low95_young if low95_young>maxi
qui replace maxi=high95_old if high95_old>maxi
qui replace maxi=low95_old if low95_old>maxi
qui egen maxval=max(maxi)

qui gen mini=high95_young
qui replace mini=low95_young if low95_young<mini
qui replace mini=high95_old if high95_old<mini
qui replace mini=low95_old if low95_old<mini
qui egen minval=min(mini)

local max_scale=maxval
local min_scale=minval
local range = (maxval - minval)
local pad = 0.10*(`range')
local min_scale = round(minval - `pad', 1000)
local max_scale = round(maxval + `pad', 1000)
local int_scale=round(((`max_scale' - `min_scale')/5), 5000)
local max_scale = max(round(maxval + `pad', 1000),1000,(`min_scale'+(`int_scale'*5)))


twoway rcap low95_young high95_young regyr, title(`Y', ring(12)) ytitle(Regression coefficients (dollars)) xtitle(Year) xlabel(1990 "1990 5pct" 2000 "2000 5pct" 2009 "2005-2009" 2014 "2010-2014" 2019 "2015-2019", labsize(small) nogrid) xmlabel(1990 "15-22 y.o." 2000 "25-32 y.o." 2009 "30-41 y.o." 2014 "35-46 y.o." 2019 "40-51 y.o.", labsize(vsmall) labgap(4)) msize(large) graphregion(margin(l+2 r+5)) graphregion(color(white)) bgcolor(white) yscale(range(`min_scale' `max_scale')) ylabel(`min_scale'(`int_scale')`max_scale', nogrid format(%9.0fc) labsize(vsmall)) lcolor(green) legend(rows(1) order(2 "young AHA" 4 "older AHA") position(6) ring(3)) note("ages of young AHA group in each time period are included in text below x-axis") || scatter b_young regyr, connect(l) lpattern(dash) mcolor(green) lcolor(green) msize(medlarge) yline(0, lwidth(large) lcolor(dkgreen) lpattern(solid)) msymbol(diamond) || rcap low95_old high95_old regyr, msize(large) lcolor(midblue) || scatter b_old regyr, connect(l) lpattern(shortdash) mcolor(midblue) lcolor(midblue) msize(medlarge) msymbol(circle)
graph export ./output/figure4_`Y'.pdf, replace	

restore
}

******************************************************************************************
**Figure 5: Extended analysis of wages and income relative to white US natives

use if inlist(compgrp, 0, 1, 3, 4, 5) using ./temp/CoreData.dta, clear
drop if regyr==.
qui sort regyr
qui g long nobs=.
qui g b_young=.
qui g b_old=.
qui g b_minority=.
qui g b_cmpim=.
qui g se_young=.
qui g se_old=.
qui g se_minority=.
qui g se_cmpim=.
qui g low95_young=.
qui g high95_young=.
qui g low95_old=.
qui g high95_old=.
qui g low95_minority=.
qui g high95_minority=.
qui g low95_cmpim=.
qui g high95_cmpim=.

foreach Y in incwage inctot {

preserve

foreach z of num 1990 2000 2009 2014 2019 {
qui areg `Y' ib3.compgrp age gender if regyr==`z', absorb(statefip) vce(cluster statefip) allbaselevels
qui replace nobs=e(N) if regyr==`z'
matrix M = r(table)
qui replace b_young=M[1,1] if regyr==`z'
qui replace b_old=M[1,2] if regyr==`z'
qui replace b_minority=M[1,4] if regyr==`z'
qui replace b_cmpim=M[1,5] if regyr==`z'
qui replace se_young=M[2,1] if regyr==`z'
qui replace se_old=M[2,2] if regyr==`z'
qui replace se_minority=M[2,4] if regyr==`z'
qui replace se_cmpim=M[2,5] if regyr==`z'
qui replace low95_young=M[5,1] if regyr==`z'
qui replace high95_young=M[6,1] if regyr==`z'
qui replace low95_old=M[5,2] if regyr==`z'
qui replace high95_old=M[6,2] if regyr==`z'
qui replace low95_minority=M[5,4] if regyr==`z'
qui replace high95_minority=M[6,4] if regyr==`z'
qui replace low95_cmpim=M[5,5] if regyr==`z'
qui replace high95_cmpim=M[6,5] if regyr==`z'

qui replace b_young=0 if regyr==1990
qui replace b_old=0 if regyr==1990
qui replace b_minority=0 if regyr==1990
qui replace b_cmpim=0 if regyr==1990
qui replace se_young=0 if regyr==1990
qui replace se_old=0 if regyr==1990
qui replace se_minority=0 if regyr==1990
qui replace se_cmpim=0 if regyr==1990
qui replace low95_young=0 if regyr==1990
qui replace high95_young=0 if regyr==1990
qui replace low95_old=0 if regyr==1990
qui replace high95_old=0 if regyr==1990
qui replace low95_minority=0 if regyr==1990
qui replace high95_minority=0 if regyr==1990
qui replace low95_cmpim=0 if regyr==1990
qui replace high95_cmpim=0 if regyr==1990
}
by regyr, sort: gen byte counter=(_n==1)
keep if counter==1

qui gen maxi=high95_young
qui replace maxi=low95_young if low95_young>maxi
qui replace maxi=high95_old if high95_old>maxi
qui replace maxi=low95_old if low95_old>maxi
qui replace maxi=high95_minority if high95_minority>maxi
qui replace maxi=low95_minority if low95_minority>maxi
qui replace maxi=high95_cmpim if high95_cmpim>maxi
qui replace maxi=low95_cmpim if low95_cmpim>maxi
qui egen maxval=max(maxi)

qui gen mini=high95_young
qui replace mini=low95_young if low95_young<mini
qui replace mini=high95_old if high95_old<mini
qui replace mini=low95_old if low95_old<mini
qui replace mini=high95_minority if high95_minority<mini
qui replace mini=low95_minority if low95_minority<mini
qui replace mini=high95_cmpim if high95_cmpim<mini
qui replace mini=low95_cmpim if low95_cmpim<mini
qui egen minval=min(mini)

local max_scale=maxval
local min_scale=minval
local range = (maxval - minval)
local pad = 0.10*(`range')
local min_scale = round(minval - `pad', 0.1)
local max_scale = round(maxval + `pad', 0.1)
local int_scale=round(((`max_scale' - `min_scale')/5), 0.05)

twoway rcap low95_young high95_young regyr, title(`Y', ring(12)) ytitle(Regression coefficients) xtitle(Year) xlabel(1990 "1990 5pct" 2000 "2000 5pct" 2009 "2005-2009" 2014 "2010-2014" 2019 "2015-2019", labsize(small) nogrid) xmlabel(1990 "15-22 y.o." 2000 "25-32 y.o." 2009 "30-41 y.o." 2014 "35-46 y.o." 2019 "40-51 y.o.", labsize(vsmall) labgap(4)) msize(large) graphregion(margin(l+2 r+5)) graphregion(color(white)) bgcolor(white) yscale(range(`min_scale' `max_scale')) ylabel(`min_scale'(`int_scale')`max_scale', nogrid format(%9.2f) labsize(vsmall)) lcolor(green) legend(rows(2) order(2 "young AHA" 4 "older AHA" 6 "US native minorities" 8 "non-Vietnamese immig.") size(vsmall) position(6) ring(3)) note("ages of young AHA group in each time period are included in text below x-axis") || scatter b_young regyr, connect(l) lpattern(dash) mcolor(green) lcolor(green) msize(medlarge) yline(0, lwidth(large) lcolor(dkgreen) lpattern(solid)) msymbol(diamond) || rcap low95_old high95_old regyr, msize(large) lcolor(midblue) || scatter b_old regyr, connect(l) lpattern(shortdash) mcolor(midblue) lcolor(midblue) msize(medlarge) msymbol(circle) || rcap low95_minority high95_minority regyr, lcolor(black) || scatter b_minority regyr, connect(l) lpattern(longdash_dot) mcolor(black) lcolor(black) msize(medlarge) msymbol(triangle) || rcap low95_cmpim high95_cmpim regyr, lcolor(orange) || scatter b_cmpim regyr, connect(l) lpattern(dash_dot) mcolor(orange) lcolor(orange) msize(medlarge) msymbol(smcircle)
graph export ./output/figure5_`Y'.pdf, replace

restore
}

foreach Y in linincwg lininct {

preserve

foreach z of num 1990 2000 2009 2014 2019 {
qui areg `Y' ib3.compgrp age gender if regyr==`z', absorb(statefip) vce(cluster statefip) allbaselevels
qui replace nobs=e(N) if regyr==`z'
matrix M = r(table)
qui replace b_young=M[1,1] if regyr==`z'
qui replace b_old=M[1,2] if regyr==`z'
qui replace b_minority=M[1,4] if regyr==`z'
qui replace b_cmpim=M[1,5] if regyr==`z'
qui replace se_young=M[2,1] if regyr==`z'
qui replace se_old=M[2,2] if regyr==`z'
qui replace se_minority=M[2,4] if regyr==`z'
qui replace se_cmpim=M[2,5] if regyr==`z'
qui replace low95_young=M[5,1] if regyr==`z'
qui replace high95_young=M[6,1] if regyr==`z'
qui replace low95_old=M[5,2] if regyr==`z'
qui replace high95_old=M[6,2] if regyr==`z'
qui replace low95_minority=M[5,4] if regyr==`z'
qui replace high95_minority=M[6,4] if regyr==`z'
qui replace low95_cmpim=M[5,5] if regyr==`z'
qui replace high95_cmpim=M[6,5] if regyr==`z'

qui replace b_young=0 if regyr==1990
qui replace b_old=0 if regyr==1990
qui replace b_minority=0 if regyr==1990
qui replace b_cmpim=0 if regyr==1990
qui replace se_young=0 if regyr==1990
qui replace se_old=0 if regyr==1990
qui replace se_minority=0 if regyr==1990
qui replace se_cmpim=0 if regyr==1990
qui replace low95_young=0 if regyr==1990
qui replace high95_young=0 if regyr==1990
qui replace low95_old=0 if regyr==1990
qui replace high95_old=0 if regyr==1990
qui replace low95_minority=0 if regyr==1990
qui replace high95_minority=0 if regyr==1990
qui replace low95_cmpim=0 if regyr==1990
qui replace high95_cmpim=0 if regyr==1990
}
by regyr, sort: gen byte counter=(_n==1)
keep if counter==1
qui gen maxi=high95_young
qui replace maxi=low95_young if low95_young>maxi
qui replace maxi=high95_old if high95_old>maxi
qui replace maxi=low95_old if low95_old>maxi
qui replace maxi=high95_minority if high95_minority>maxi
qui replace maxi=low95_minority if low95_minority>maxi
qui replace maxi=high95_cmpim if high95_cmpim>maxi
qui replace maxi=low95_cmpim if low95_cmpim>maxi
qui egen maxval=max(maxi)

qui gen mini=high95_young
qui replace mini=low95_young if low95_young<mini
qui replace mini=high95_old if high95_old<mini
qui replace mini=low95_old if low95_old<mini
qui replace mini=high95_minority if high95_minority<mini
qui replace mini=low95_minority if low95_minority<mini
qui replace mini=high95_cmpim if high95_cmpim<mini
qui replace mini=low95_cmpim if low95_cmpim<mini
qui egen minval=min(mini)

local max_scale=maxval
local min_scale=minval
local range = (maxval - minval)
local pad = 0.10*(`range')
local min_scale = round(minval - `pad', 1000)
local max_scale = round(maxval + `pad', 1000)
local int_scale=round(((`max_scale' - `min_scale')/5), 5000)

twoway rcap low95_young high95_young regyr, title(`Y', ring(12)) ytitle(Regression coefficients (dollars)) xtitle(Year) xlabel(1990 "1990 5pct" 2000 "2000 5pct" 2009 "2005-2009" 2014 "2010-2014" 2019 "2015-2019", labsize(small) nogrid) xmlabel(1990 "15-22 y.o." 2000 "25-32 y.o." 2009 "30-41 y.o." 2014 "35-46 y.o." 2019 "40-51 y.o.", labsize(vsmall) labgap(4)) msize(large) graphregion(margin(l+2 r+5)) graphregion(color(white)) bgcolor(white) yscale(range(`min_scale' `max_scale') titlegap(*0)) ylabel(`min_scale'(`int_scale')`max_scale', nogrid format(%9.0fc) labsize(vsmall)) lcolor(green) legend(region(margin(left right)) rows(2) order(2 "young AHA" 4 "older AHA" 6 "US native minorities" 8 "non-Vietnamese imm.") size(vsmall) position(6) ring(3)) note("ages of young AHA group in each time period are included in text below x-axis") || scatter b_young regyr, connect(l) lpattern(dash) mcolor(green) lcolor(green) msize(medlarge) yline(0, lwidth(large) lcolor(dkgreen) lpattern(solid)) msymbol(diamond) || rcap low95_old high95_old regyr, msize(large) lcolor(midblue) || scatter b_old regyr, connect(l) lpattern(shortdash) mcolor(midblue) lcolor(midblue) msize(medlarge) msymbol(circle) || rcap low95_minority high95_minority regyr, lcolor(black) || scatter b_minority regyr, connect(l) lpattern(longdash_dot) mcolor(black) lcolor(black) msize(medlarge) msymbol(triangle) || rcap low95_cmpim high95_cmpim regyr, lcolor(orange) || scatter b_cmpim regyr, connect(l) lpattern(dash_dot) mcolor(orange) lcolor(orange) msize(medlarge) msymbol(smcircle)
graph export ./output/figure5_`Y'.pdf, replace

restore
}

******************************************************************************************
**Figure 6: Distribution by US income deciles in 2015-2019

use compgrp lininct vi yrimmig perwt byr young regyr if regyr==2019 using ./temp/CoreData.dta, clear

qui g USlininct=lininct if compgrp==3 | compgrp==4

pctile incbin=USlininct [fw=perwt], nq(10)

xtile dis=lininct if compgrp==0 | compgrp==1, cutpoints(incbin)

keep if compgrp==0 | compgrp==1

collapse (count) raw_ct=lininct (sum) wtdpop_ct=perwt, by(compgrp dis)

export delimited using ./output/figure6.csv, replace


******************************************************************************************
**Table 1: Regressions of young versus older AHA immigrant arrivals using 2015-2019 ACS

***Regressions with base controls

use ewell yrseduc HSup colup emp unemp ninlf lininct inctot linincwg incwage regyr compgrp young age gender statefip cluster col perwt ct occ occdesc category if regyr==2019 & inlist(compgrp, 0, 1) using ./temp/CoreData.dta, clear

preserve

foreach Y in ewell yrseduc HSup colup emp unemp ninlf lininct inctot linincwg incwage {
qui eststo: areg `Y' young age gender, absorb(statefip) vce(cluster statefip)
}

esttab _all using ./output/table1_wbasecontrols.csv, keep(young) cells(b(star fmt(3)) se(par)) par stats(N) starlevels(+ 0.10 ++ 0.05 +++ .01) nogap title(Regressions with base controls, 2015-2019 ACS) replace 

***Regressions adding controls for education and fluency

eststo clear

foreach Y in emp unemp ninlf lininct inctot linincwg incwage {
qui eststo: areg `Y' young age gender ewell HSup col, absorb(statefip) vce(cluster statefip)
}

esttab _all using ./output/table1_wcontrolsforeducandfluenc.csv, keep(young) cells(b(star fmt(3)) se(par)) par stats(N) starlevels(+ 0.10 ++ 0.05 +++ .01) nogap title(Regressions adding controls for education and fluency, 2015-2019 ACS) replace 

**Mean Values**

collapse (mean) ewell yrseduc HSup colup emp unemp ninlf lininct inctot linincwg incwage, by(compgrp) fast

qui order ewell yrseduc HSup colup emp unemp ninlf lininct inctot linincwg incwage

qui sort compgrp
drop compgrp

xpose, clear varname

qui order _varname v1 v2
qui rename v1 youngAHA
qui rename v2 olderAHA

export excel using ./output/table1_meanvalues.xls, firstrow(variables) replace

**modify formatting
putexcel set ./output/table1_meanvalues.xls, modify

putexcel (B2:C2) (B4:C8), nformat(percent_d2) overwritefmt

putexcel (B3:C3) (B10:C10) (B12:C12), nformat(#.0) overwritefmt

putexcel (B9:C9) (B11:C11), nformat(accountcur) overwritefmt

******************************************************************************************
**Table 3: Occupations of young and older AHA immigrants in 2015-2019 ACS

***A. Percent distribution over broad occupational categories

restore 

keep occ occdesc compgrp perwt emp regyr category
keep if emp==1

eststo clear
eststo: qui estpost tab category compgrp [fw=perwt]
esttab using ./output/table3a.csv, cell(colpct(fmt(2))) unstack noobs modelwidth(15) varlabels(`e(labels)') eqlabels(`e(eqlabels)') replace plain

***B. Detailed occupations with highest overrepresentation of young arrivals

qui drop if compgrp==.

preserve
    qui contract occdesc compgrp [fw=perwt], freq(count)
    qui bysort compgrp (occdesc): egen total = total(count)
    qui gen colpct = 100 * count / total
    qui keep occdesc compgrp colpct
    qui reshape wide colpct, i(occdesc) j(compgrp)
    foreach x of varlist colpct0 colpct1{
    	qui replace `x' = 0 if missing(`x')
    }
    qui rename colpct0 youngAHA
    qui rename colpct1 olderAHA
    qui gen diff = youngAHA - olderAHA
    qui gsort -diff
    list occdesc youngAHA olderAHA diff in 1/5, abbreviate(30)
restore

***C. Detailed occupations with highest underrepresentation of young arrivals

preserve
    qui contract occdesc compgrp [fw=perwt], freq(count)
    qui bysort compgrp (occdesc): egen total = total(count)
    qui gen colpct = 100 * count / total
    qui keep occdesc compgrp colpct
    qui reshape wide colpct, i(occdesc) j(compgrp)
    foreach x of varlist colpct0 colpct1{
    	qui replace `x' = 0 if missing(`x')
    }
    qui rename colpct0 youngAHA
    qui rename colpct1 olderAHA
    qui gen diff = youngAHA - olderAHA
    qui gsort diff
    list occdesc youngAHA olderAHA diff in 1/5, abbreviate(30)
restore

***D. Detailed occupations with supervisory or managerial key words

*Detailed occupation description includes words "Managers" "Supervisors" or "Chief executives"

    qui contract occdesc compgrp [fw=perwt], freq(count)
    qui bysort compgrp (occdesc): egen total = total(count)
    qui gen colpct = 100 * count / total
    qui keep occdesc compgrp colpct
    qui reshape wide colpct, i(occdesc) j(compgrp)
    foreach x of varlist colpct0 colpct1{
    	qui replace `x' = 0 if missing(`x')
    }
    qui rename colpct0 youngAHA
    qui rename colpct1 olderAHA
    qui gen superv = ustrregexm(occdesc,"Supervisors",1)
    tabstat youngAHA olderAHA if superv==1, stat(sum)
    qui gen mgr = ustrregexm(occdesc,"Managers",1) | ustrregexm(occdesc,"Chief executives",1)
    tabstat youngAHA olderAHA if mgr==1, stat(sum)


******************************************************************************************
**Table 4: Gelbach decomposition and mediation analysis of ACS wage and salary income 2015-2019

use year ageimm compgrp ewell young age gender statefip incwage HS scol col linincwg emp unemp ninlf lininct inctot linincwg incwage marst marcolsp marnonanc marnatsp ownershp linvalueh valueh linrentg maxpuma pc_vpuma if year>=2015 & year<=2019 & (compgrp==0 | compgrp==1) using ./temp/CoreData.dta, clear

eststo clear 

qui gen low=(HS==0 & scol==0 & col==0)
qui sum low HS scol col
qui gen HS2=1-low

xi i.statefip
local ctrl "age gender _I*"

foreach var of varlist incwage linincwg {
eststo clear
eststo: qui areg `var' young age gender, absorb(statefip) vce(cluster statefip)
esttab, cells("b se") keep(young) nostar noobs
eststo clear
eststo: qui areg `var' young HS2 ewell col age gender, absorb(statefip) vce(cluster statefip)
esttab, cells("b se") keep(young) nostar noobs
eststo clear
*Gelbach composition of difference
eststo: qui b1x2 `var', x1all(young age gender _I*) x2all(ewell HS2 col) x1only(young) x2delta(g1 = ewell : g2=HS2 col) cl(statefip) nobase nofull
esttab, cells("b se") nostar noobs
eststo clear
*Mediation analysis of explanatory variables in isolation
eststo: qui areg `var' young age gender ewell, absorb(statefip) vce(cluster statefip)
esttab, cells("b se") keep(young) nostar noobs
eststo clear
qui mediate (`var' `ctrl') (ewell `ctrl') (young), vce(cl statefip) conv_maxiter(5) nie te
matrix med1=r(table)
local nie1=med1[1,1]
local te1=med1[1,2]
di "NIE:" `nie1'
di "TE:" `te1'
eststo: qui areg `var' young age gender HS2, absorb(statefip) vce(cluster statefip)
esttab, cells("b se") keep(young) nostar noobs
eststo clear
qui mediate (`var' `ctrl') (HS2 `ctrl') (young), vce(cl statefip) conv_maxiter(5) nie te
matrix med2=r(table)
local nie2=med2[1,1]
local te2=med2[1,2]
di "NIE:" `nie2'
di "TE:" `te2'
eststo: qui areg `var' young age gender col, absorb(statefip) vce(cluster statefip)
esttab, cells("b se") keep(young) nostar noobs
eststo clear
qui mediate (`var' `ctrl') (col `ctrl') (young), vce(cl statefip) conv_maxiter(5) nie te
matrix med3=r(table)
local nie3=med3[1,1]
local te3=med3[1,2]
di "NIE:"`nie3'
di "TE:" `te3'
}


*******************
*******************
**Appendix Output**
*******************
*******************


******************************************************************************************
**Appendix Figure 3: Figure 3 with age at arrival split for non-Vietnamese immigrant comparison group

use ewell yrseduc HSup colup incwage inctot linincwg lininct compgrp age gender regyr cluster statefip ageimm if inlist(compgrp, 0, 1, 3, 4, 5) using ./temp/CoreData.dta, clear
	
qui replace compgrp=6 if compgrp==5 & ageimm>=14 & ageimm<=17
qui replace compgrp=7 if compgrp==5 & ageimm>=18 & ageimm<=21
qui label define compgrp_lbl 6 "Young non-Vietnamese immigrants" 7 "Older non-Vietnamese immigrants", replace

drop if regyr==.
qui sort regyr
qui gen long nobs=.
qui g b_young=.
qui g b_old=.
qui g b_minority=.
qui g b_cmpim_young=.
qui g b_cmpim_old=.
qui g se_young=.
qui g se_old=.
qui g se_minority=.
qui g se_cmpim_young=.
qui g se_cmpim_old=.
qui g low95_young=.
qui g high95_young=.
qui g low95_old=.
qui g high95_old=.
qui g low95_minority=.
qui g high95_minority=.
qui g low95_cmpim_young=.
qui g high95_cmpim_young=.
qui g low95_cmpim_old=.
qui g high95_cmpim_old=.

foreach Y in ewell yrseduc {

preserve 

foreach z of num 1990 2000 2009 2014 2019 {
qui areg `Y' ib3.compgrp age gender if regyr==`z', absorb(statefip) vce(cluster statefip) allbaselevels
qui replace nobs=e(N) if regyr==`z'
matrix M = r(table)
qui replace b_young=M[1,1] if regyr==`z'
qui replace b_old=M[1,2] if regyr==`z'
qui replace b_minority=M[1,4] if regyr==`z'
qui replace b_cmpim_young=M[1,5] if regyr==`z'
qui replace b_cmpim_old=M[1,6] if regyr==`z'

qui replace se_young=M[2,1] if regyr==`z'
qui replace se_old=M[2,2] if regyr==`z'
qui replace se_minority=M[2,4] if regyr==`z'
qui replace se_cmpim_young=M[2,5] if regyr==`z'
qui replace se_cmpim_old=M[2,6] if regyr==`z'

qui replace low95_young=M[5,1] if regyr==`z'
qui replace high95_young=M[6,1] if regyr==`z'
qui replace low95_old=M[5,2] if regyr==`z'
qui replace high95_old=M[6,2] if regyr==`z'
qui replace low95_minority=M[5,4] if regyr==`z'
qui replace high95_minority=M[6,4] if regyr==`z'
qui replace low95_cmpim_young=M[5,5] if regyr==`z'
qui replace high95_cmpim_young=M[6,5] if regyr==`z'
qui replace low95_cmpim_old=M[5,6] if regyr==`z'
qui replace high95_cmpim_old=M[6,6] if regyr==`z'
}
by regyr, sort: gen byte counter=(_n==1)
keep if counter==1
qui gen maxi=high95_young
qui replace maxi=low95_young if low95_young>maxi
qui replace maxi=high95_old if high95_old>maxi
qui replace maxi=low95_old if low95_old>maxi
qui replace maxi=high95_minority if high95_minority>maxi
qui replace maxi=low95_minority if low95_minority>maxi
qui replace maxi=high95_cmpim_young if high95_cmpim_young>maxi
qui replace maxi=low95_cmpim_young if low95_cmpim_young>maxi
qui replace maxi=high95_cmpim_old if high95_cmpim_old>maxi
qui replace maxi=low95_cmpim_old if low95_cmpim_old>maxi
qui egen maxval=max(maxi)

qui gen mini=high95_young
qui replace mini=low95_young if low95_young<mini
qui replace mini=high95_old if high95_old<mini
qui replace mini=low95_old if low95_old<mini
qui replace mini=high95_minority if high95_minority<mini
qui replace mini=low95_minority if low95_minority<mini
qui replace mini=high95_cmpim_young if high95_cmpim_young<mini
qui replace mini=low95_cmpim_young if low95_cmpim_young<mini
qui replace mini=high95_cmpim_old if high95_cmpim_old<mini
qui replace mini=low95_cmpim_old if low95_cmpim_old<mini
qui egen minval=min(mini)

local max_scale=maxval
local min_scale=minval
local range = (maxval - minval)
local pad = 0.10*(`range')
local min_scale = round(minval - `pad', 0.1)
local max_scale = round(maxval + `pad', 0.1)
local int_scale=round(((`max_scale' - `min_scale')/5), 0.05)
local max_scale = max(round(maxval + `pad', 0.1),0.1,(`min_scale'+(`int_scale'*5)))


twoway rcap low95_young high95_young regyr, title(`Y', ring(12)) ytitle(Regression coefficients, margin(small)) xtitle(Year) xlabel(1990 "1990 5pct" 2000 "2000 5pct" 2009 "2005-2009" 2014 "2010-2014" 2019 "2015-2019", labsize(small) nogrid) xmlabel(1990 "15-22 y.o." 2000 "25-32 y.o." 2009 "30-41 y.o." 2014 "35-46 y.o." 2019 "40-51 y.o.", labsize(vsmall) labgap(4)) msize(large) graphregion(margin(l+2 r+5)) graphregion(color(white)) bgcolor(white) yscale(range(`min_scale' `max_scale')) ylabel(`min_scale'(`int_scale')`max_scale', nogrid format(%9.2f) labsize(vsmall)) yscale(titlegap(*5)) lcolor(green) legend(rows(3) order(2 "young AHA" 4 "older AHA" 6 "US native minorities" 8 "young non-Vietnamese immig." 10 "older non-Vietnamese immig.") size(vsmall) position(6) ring(3)) note("ages of young AHA group in each time period are included in text below x-axis") || scatter b_young regyr, connect(l) lpattern(dash) mcolor(green) lcolor(green) msize(medlarge) yline(0, lwidth(large) lcolor(dkgreen) lpattern(solid)) msymbol(diamond) || rcap low95_old high95_old regyr, msize(large) lcolor(midblue) || scatter b_old regyr, connect(l) lpattern(shortdash) mcolor(midblue) lcolor(midblue) msize(medlarge) msymbol(circle) || rcap low95_minority high95_minority regyr, lcolor(black) || scatter b_minority regyr, connect(l) lpattern(longdash_dot) mcolor(black) lcolor(black) msize(medlarge) msymbol(triangle) || rcap low95_cmpim_young high95_cmpim_young regyr, lcolor(dkorange) || scatter b_cmpim_young regyr, connect(l) lpattern(dash_dot) mcolor(dkorange) lcolor(dkorange) msize(medlarge) msymbol(smdiamond) || rcap low95_cmpim_old high95_cmpim_old regyr, lcolor(red) || scatter b_cmpim_old regyr, connect(l) lpattern(shortdash_dot) mcolor(red) lcolor(red) msize(medlarge) msymbol(smtriangle)
graph export ./output/app_figure3_`Y'.pdf, replace

restore
}


foreach Y in HSup {

preserve

foreach z of num 1990 2000 2009 2014 2019 {
qui areg `Y' ib3.compgrp age gender if regyr==`z', absorb(statefip) vce(cluster statefip) allbaselevels
qui replace nobs=e(N) if regyr==`z'
matrix M = r(table)
qui replace b_young=M[1,1] if regyr==`z'
qui replace b_old=M[1,2] if regyr==`z'
qui replace b_minority=M[1,4] if regyr==`z'
qui replace b_cmpim_young=M[1,5] if regyr==`z'
qui replace b_cmpim_old=M[1,6] if regyr==`z'

qui replace se_young=M[2,1] if regyr==`z'
qui replace se_old=M[2,2] if regyr==`z'
qui replace se_minority=M[2,4] if regyr==`z'
qui replace se_cmpim_young=M[2,5] if regyr==`z'
qui replace se_cmpim_old=M[2,6] if regyr==`z'

qui replace low95_young=M[5,1] if regyr==`z'
qui replace high95_young=M[6,1] if regyr==`z'
qui replace low95_old=M[5,2] if regyr==`z'
qui replace high95_old=M[6,2] if regyr==`z'
qui replace low95_minority=M[5,4] if regyr==`z'
qui replace high95_minority=M[6,4] if regyr==`z'
qui replace low95_cmpim_young=M[5,5] if regyr==`z'
qui replace high95_cmpim_young=M[6,5] if regyr==`z'
qui replace low95_cmpim_old=M[5,6] if regyr==`z'
qui replace high95_cmpim_old=M[6,6] if regyr==`z'

qui replace b_young=0 if regyr==1990
qui replace b_old=0 if regyr==1990
qui replace b_minority=0 if regyr==1990
qui replace b_cmpim_young=0 if regyr==1990
qui replace b_cmpim_old=0 if regyr==1990

qui replace se_young=0 if regyr==1990
qui replace se_old=0 if regyr==1990
qui replace se_minority=0 if regyr==1990
qui replace se_cmpim_young=0 if regyr==1990
qui replace se_cmpim_old=0 if regyr==1990

qui replace low95_young=0 if regyr==1990
qui replace high95_young=0 if regyr==1990
qui replace low95_old=0 if regyr==1990
qui replace high95_old=0 if regyr==1990
qui replace low95_minority=0 if regyr==1990
qui replace high95_minority=0 if regyr==1990
qui replace low95_cmpim_young=0 if regyr==1990
qui replace high95_cmpim_young=0 if regyr==1990
qui replace low95_cmpim_old=0 if regyr==1990
qui replace high95_cmpim_old=0 if regyr==1990

}
by regyr, sort: gen byte counter=(_n==1)
keep if counter==1
qui gen maxi=high95_young
qui replace maxi=low95_young if low95_young>maxi
qui replace maxi=high95_old if high95_old>maxi
qui replace maxi=low95_old if low95_old>maxi
qui replace maxi=high95_minority if high95_minority>maxi
qui replace maxi=low95_minority if low95_minority>maxi
qui replace maxi=high95_cmpim_young if high95_cmpim_young>maxi
qui replace maxi=low95_cmpim_young if low95_cmpim_young>maxi
qui replace maxi=high95_cmpim_old if high95_cmpim_old>maxi
qui replace maxi=low95_cmpim_old if low95_cmpim_old>maxi
qui egen maxval=max(maxi)

qui gen mini=high95_young
qui replace mini=low95_young if low95_young<mini
qui replace mini=high95_old if high95_old<mini
qui replace mini=low95_old if low95_old<mini
qui replace mini=high95_minority if high95_minority<mini
qui replace mini=low95_minority if low95_minority<mini
qui replace mini=high95_cmpim_young if high95_cmpim_young<mini
qui replace mini=low95_cmpim_young if low95_cmpim_young<mini
qui replace mini=high95_cmpim_old if high95_cmpim_old<mini
qui replace mini=low95_cmpim_old if low95_cmpim_old<mini
qui egen minval=min(mini)

local min_scale = -0.3
local max_scale = 0.1
local int_scale=round(((`max_scale' - `min_scale')/4), 0.05)

twoway rcap low95_young high95_young regyr, title(`Y', ring(12)) ytitle(Regression coefficients, margin(small)) xtitle(Year) xlabel(1990 "1990 5pct" 2000 "2000 5pct" 2009 "2005-2009" 2014 "2010-2014" 2019 "2015-2019", labsize(small) nogrid) xmlabel(1990 "15-22 y.o." 2000 "25-32 y.o." 2009 "30-41 y.o." 2014 "35-46 y.o." 2019 "40-51 y.o.", labsize(vsmall) labgap(4)) msize(large) graphregion(margin(l+2 r+5)) graphregion(color(white)) bgcolor(white) yscale(range(`min_scale' `max_scale')) ylabel(`min_scale'(`int_scale')`max_scale', nogrid format(%9.2f) labsize(vsmall)) yscale(titlegap(*5)) lcolor(green) legend(rows(3) order(2 "young AHA" 4 "older AHA" 6 "US native minorities" 8 "young non-Vietnamese immig." 10 "older non-Vietnamese immig.") size(vsmall) position(6) ring(3)) note("ages of young AHA group in each time period are included in text below x-axis") || scatter b_young regyr, connect(l) lpattern(dash) mcolor(green) lcolor(green) msize(medlarge) yline(0, lwidth(large) lcolor(dkgreen) lpattern(solid)) msymbol(diamond) || rcap low95_old high95_old regyr, msize(large) lcolor(midblue) || scatter b_old regyr, connect(l) lpattern(shortdash) mcolor(midblue) lcolor(midblue) msize(medlarge) msymbol(circle) || rcap low95_minority high95_minority regyr, lcolor(black) || scatter b_minority regyr, connect(l) lpattern(longdash_dot) mcolor(black) lcolor(black) msize(medlarge) msymbol(triangle) || rcap low95_cmpim_young high95_cmpim_young regyr, lcolor(dkorange) || scatter b_cmpim_young regyr, connect(l) lpattern(dash_dot) mcolor(dkorange) lcolor(dkorange) msize(medlarge) msymbol(smdiamond) || rcap low95_cmpim_old high95_cmpim_old regyr, lcolor(red) || scatter b_cmpim_old regyr, connect(l) lpattern(shortdash_dot) mcolor(red) lcolor(red) msize(medlarge) msymbol(smtriangle)
graph export ./output/app_figure3_`Y'.pdf, replace

restore
}


foreach Y in colup {

preserve

foreach z of num 1990 2000 2009 2014 2019 {
qui areg `Y' ib3.compgrp age gender if regyr==`z', absorb(statefip) vce(cluster statefip) allbaselevels
qui replace nobs=e(N) if regyr==`z'
matrix M = r(table)
qui replace b_young=M[1,1] if regyr==`z'
qui replace b_old=M[1,2] if regyr==`z'
qui replace b_minority=M[1,4] if regyr==`z'
qui replace b_cmpim_young=M[1,5] if regyr==`z'
qui replace b_cmpim_old=M[1,6] if regyr==`z'

qui replace se_young=M[2,1] if regyr==`z'
qui replace se_old=M[2,2] if regyr==`z'
qui replace se_minority=M[2,4] if regyr==`z'
qui replace se_cmpim_young=M[2,5] if regyr==`z'
qui replace se_cmpim_old=M[2,6] if regyr==`z'

qui replace low95_young=M[5,1] if regyr==`z'
qui replace high95_young=M[6,1] if regyr==`z'
qui replace low95_old=M[5,2] if regyr==`z'
qui replace high95_old=M[6,2] if regyr==`z'
qui replace low95_minority=M[5,4] if regyr==`z'
qui replace high95_minority=M[6,4] if regyr==`z'
qui replace low95_cmpim_young=M[5,5] if regyr==`z'
qui replace high95_cmpim_young=M[6,5] if regyr==`z'
qui replace low95_cmpim_old=M[5,6] if regyr==`z'
qui replace high95_cmpim_old=M[6,6] if regyr==`z'

qui replace b_young=0 if regyr==1990
qui replace b_old=0 if regyr==1990
qui replace b_minority=0 if regyr==1990
qui replace b_cmpim_young=0 if regyr==1990
qui replace b_cmpim_old=0 if regyr==1990

qui replace se_young=0 if regyr==1990
qui replace se_old=0 if regyr==1990
qui replace se_minority=0 if regyr==1990
qui replace se_cmpim_young=0 if regyr==1990
qui replace se_cmpim_old=0 if regyr==1990

qui replace low95_young=0 if regyr==1990
qui replace high95_young=0 if regyr==1990
qui replace low95_old=0 if regyr==1990
qui replace high95_old=0 if regyr==1990
qui replace low95_minority=0 if regyr==1990
qui replace high95_minority=0 if regyr==1990
qui replace low95_cmpim_young=0 if regyr==1990
qui replace high95_cmpim_young=0 if regyr==1990
qui replace low95_cmpim_old=0 if regyr==1990
qui replace high95_cmpim_old=0 if regyr==1990

}
by regyr, sort: gen byte counter=(_n==1)
keep if counter==1
qui gen maxi=high95_young
qui replace maxi=low95_young if low95_young>maxi
qui replace maxi=high95_old if high95_old>maxi
qui replace maxi=low95_old if low95_old>maxi
qui replace maxi=high95_minority if high95_minority>maxi
qui replace maxi=low95_minority if low95_minority>maxi
qui replace maxi=high95_cmpim_young if high95_cmpim_young>maxi
qui replace maxi=low95_cmpim_young if low95_cmpim_young>maxi
qui replace maxi=high95_cmpim_old if high95_cmpim_old>maxi
qui replace maxi=low95_cmpim_old if low95_cmpim_old>maxi
qui egen maxval=max(maxi)

qui gen mini=high95_young
qui replace mini=low95_young if low95_young<mini
qui replace mini=high95_old if high95_old<mini
qui replace mini=low95_old if low95_old<mini
qui replace mini=high95_minority if high95_minority<mini
qui replace mini=low95_minority if low95_minority<mini
qui replace mini=high95_cmpim_young if high95_cmpim_young<mini
qui replace mini=low95_cmpim_young if low95_cmpim_young<mini
qui replace mini=high95_cmpim_old if high95_cmpim_old<mini
qui replace mini=low95_cmpim_old if low95_cmpim_old<mini
qui egen minval=min(mini)

local min_scale = -0.2
local max_scale = 0.2
local int_scale=round(((`max_scale' - `min_scale')/4), 0.05)

twoway rcap low95_young high95_young regyr, title(`Y', ring(12)) ytitle(Regression coefficients, margin(small)) xtitle(Year) xlabel(1990 "1990 5pct" 2000 "2000 5pct" 2009 "2005-2009" 2014 "2010-2014" 2019 "2015-2019", labsize(small) nogrid) xmlabel(1990 "15-22 y.o." 2000 "25-32 y.o." 2009 "30-41 y.o." 2014 "35-46 y.o." 2019 "40-51 y.o.", labsize(vsmall) labgap(4)) msize(large) graphregion(margin(l+2 r+5)) graphregion(color(white)) bgcolor(white) yscale(range(`min_scale' `max_scale')) ylabel(`min_scale'(`int_scale')`max_scale', nogrid format(%9.2f) labsize(vsmall)) yscale(titlegap(*5)) lcolor(green) legend(rows(3) order(2 "young AHA" 4 "older AHA" 6 "US native minorities" 8 "young non-Vietnamese immig." 10 "older non-Vietnamese immig.") size(vsmall) position(6) ring(3)) note("ages of young AHA group in each time period are included in text below x-axis") || scatter b_young regyr, connect(l) lpattern(dash) mcolor(green) lcolor(green) msize(medlarge) yline(0, lwidth(large) lcolor(dkgreen) lpattern(solid)) msymbol(diamond) || rcap low95_old high95_old regyr, msize(large) lcolor(midblue) || scatter b_old regyr, connect(l) lpattern(shortdash) mcolor(midblue) lcolor(midblue) msize(medlarge) msymbol(circle) || rcap low95_minority high95_minority regyr, lcolor(black) || scatter b_minority regyr, connect(l) lpattern(longdash_dot) mcolor(black) lcolor(black) msize(medlarge) msymbol(triangle) || rcap low95_cmpim_young high95_cmpim_young regyr, lcolor(dkorange) || scatter b_cmpim_young regyr, connect(l) lpattern(dash_dot) mcolor(dkorange) lcolor(dkorange) msize(medlarge) msymbol(smdiamond) || rcap low95_cmpim_old high95_cmpim_old regyr, lcolor(red) || scatter b_cmpim_old regyr, connect(l) lpattern(shortdash_dot) mcolor(red) lcolor(red) msize(medlarge) msymbol(smtriangle)
graph export ./output/app_figure3_`Y'.pdf, replace

restore
}

******************************************************************************************
**Appendix Figure 4: Figure 5 with age at arrival split for non-Vietnamese immigrant comparison group
	

foreach Y in incwage inctot {
	
preserve

foreach z of num 1990 2000 2009 2014 2019 {
qui areg `Y' ib3.compgrp age gender if regyr==`z', absorb(statefip) vce(cluster statefip) allbaselevels
qui replace nobs=e(N) if regyr==`z'
matrix M = r(table)
qui replace b_young=M[1,1] if regyr==`z'
qui replace b_old=M[1,2] if regyr==`z'
qui replace b_minority=M[1,4] if regyr==`z'
qui replace b_cmpim_young=M[1,5] if regyr==`z'
qui replace b_cmpim_old=M[1,6] if regyr==`z'

qui replace se_young=M[2,1] if regyr==`z'
qui replace se_old=M[2,2] if regyr==`z'
qui replace se_minority=M[2,4] if regyr==`z'
qui replace se_cmpim_young=M[2,5] if regyr==`z'
qui replace se_cmpim_old=M[2,6] if regyr==`z'

qui replace low95_young=M[5,1] if regyr==`z'
qui replace high95_young=M[6,1] if regyr==`z'
qui replace low95_old=M[5,2] if regyr==`z'
qui replace high95_old=M[6,2] if regyr==`z'
qui replace low95_minority=M[5,4] if regyr==`z'
qui replace high95_minority=M[6,4] if regyr==`z'
qui replace low95_cmpim_young=M[5,5] if regyr==`z'
qui replace high95_cmpim_young=M[6,5] if regyr==`z'
qui replace low95_cmpim_old=M[5,6] if regyr==`z'
qui replace high95_cmpim_old=M[6,6] if regyr==`z'

qui replace b_young=0 if regyr==1990
qui replace b_old=0 if regyr==1990
qui replace b_minority=0 if regyr==1990
qui replace b_cmpim_young=0 if regyr==1990
qui replace b_cmpim_old=0 if regyr==1990

qui replace se_young=0 if regyr==1990
qui replace se_old=0 if regyr==1990
qui replace se_minority=0 if regyr==1990
qui replace se_cmpim_young=0 if regyr==1990
qui replace se_cmpim_old=0 if regyr==1990

qui replace low95_young=0 if regyr==1990
qui replace high95_young=0 if regyr==1990
qui replace low95_old=0 if regyr==1990
qui replace high95_old=0 if regyr==1990
qui replace low95_minority=0 if regyr==1990
qui replace high95_minority=0 if regyr==1990
qui replace low95_cmpim_young=0 if regyr==1990
qui replace high95_cmpim_young=0 if regyr==1990
qui replace low95_cmpim_old=0 if regyr==1990
qui replace high95_cmpim_old=0 if regyr==1990

}
by regyr, sort: gen byte counter=(_n==1)
keep if counter==1
qui gen maxi=high95_young
qui replace maxi=low95_young if low95_young>maxi
qui replace maxi=high95_old if high95_old>maxi
qui replace maxi=low95_old if low95_old>maxi
qui replace maxi=high95_minority if high95_minority>maxi
qui replace maxi=low95_minority if low95_minority>maxi
qui replace maxi=high95_cmpim_young if high95_cmpim_young>maxi
qui replace maxi=low95_cmpim_young if low95_cmpim_young>maxi
qui replace maxi=high95_cmpim_old if high95_cmpim_old>maxi
qui replace maxi=low95_cmpim_old if low95_cmpim_old>maxi
qui egen maxval=max(maxi)

qui gen mini=high95_young
qui replace mini=low95_young if low95_young<mini
qui replace mini=high95_old if high95_old<mini
qui replace mini=low95_old if low95_old<mini
qui replace mini=high95_minority if high95_minority<mini
qui replace mini=low95_minority if low95_minority<mini
qui replace mini=high95_cmpim_young if high95_cmpim_young<mini
qui replace mini=low95_cmpim_young if low95_cmpim_young<mini
qui replace mini=high95_cmpim_old if high95_cmpim_old<mini
qui replace mini=low95_cmpim_old if low95_cmpim_old<mini
qui egen minval=min(mini)

local max_scale=maxval
local min_scale=minval
local range = (maxval - minval)
local pad = 0.10*(`range')
local min_scale = round(minval - `pad', 0.1)
local max_scale = round(maxval + `pad', 0.1)
local int_scale=round(((`max_scale' - `min_scale')/5), 0.05)
local max_scale = max(round(maxval + `pad', 0.1),0.1,(`min_scale'+(`int_scale'*5)))

twoway rcap low95_young high95_young regyr, title(`Y', ring(12)) ytitle(Regression coefficients, margin(small)) xtitle(Year) xlabel(1990 "1990 5pct" 2000 "2000 5pct" 2009 "2005-2009" 2014 "2010-2014" 2019 "2015-2019", labsize(small) nogrid) xmlabel(1990 "15-22 y.o." 2000 "25-32 y.o." 2009 "30-41 y.o." 2014 "35-46 y.o." 2019 "40-51 y.o.", labsize(vsmall) labgap(4)) msize(large) graphregion(margin(l+2 r+5)) graphregion(color(white)) bgcolor(white) yscale(range(`min_scale' `max_scale')) ylabel(`min_scale'(`int_scale')`max_scale', nogrid format(%9.2f) labsize(vsmall)) yscale(titlegap(*5)) lcolor(green) legend(rows(3) order(2 "young AHA" 4 "older AHA" 6 "US native minorities" 8 "young non-Vietnamese immig." 10 "older non-Vietnamese immig.") size(vsmall) position(6) ring(3)) note("ages of young AHA group in each time period are included in text below x-axis") || scatter b_young regyr, connect(l) lpattern(dash) mcolor(green) lcolor(green) msize(medlarge) yline(0, lwidth(large) lcolor(dkgreen) lpattern(solid)) msymbol(diamond) || rcap low95_old high95_old regyr, msize(large) lcolor(midblue) || scatter b_old regyr, connect(l) lpattern(shortdash) mcolor(midblue) lcolor(midblue) msize(medlarge) msymbol(circle) || rcap low95_minority high95_minority regyr, lcolor(black) || scatter b_minority regyr, connect(l) lpattern(longdash_dot) mcolor(black) lcolor(black) msize(medlarge) msymbol(triangle) || rcap low95_cmpim_young high95_cmpim_young regyr, lcolor(dkorange) || scatter b_cmpim_young regyr, connect(l) lpattern(dash_dot) mcolor(dkorange) lcolor(dkorange) msize(medlarge) msymbol(smdiamond) || rcap low95_cmpim_old high95_cmpim_old regyr, lcolor(red) || scatter b_cmpim_old regyr, connect(l) lpattern(shortdash_dot) mcolor(red) lcolor(red) msize(medlarge) msymbol(smtriangle)
graph export ./output/app_figure4_`Y'.pdf, replace

restore
}

foreach Y in linincwg lininct {

preserve

foreach z of num 1990 2000 2009 2014 2019 {
qui areg `Y' ib3.compgrp age gender if regyr==`z', absorb(statefip) vce(cluster statefip) allbaselevels
qui replace nobs=e(N) if regyr==`z'
matrix M = r(table)
qui replace b_young=M[1,1] if regyr==`z'
qui replace b_old=M[1,2] if regyr==`z'
qui replace b_minority=M[1,4] if regyr==`z'
qui replace b_cmpim_young=M[1,5] if regyr==`z'
qui replace b_cmpim_old=M[1,6] if regyr==`z'

qui replace se_young=M[2,1] if regyr==`z'
qui replace se_old=M[2,2] if regyr==`z'
qui replace se_minority=M[2,4] if regyr==`z'
qui replace se_cmpim_young=M[2,5] if regyr==`z'
qui replace se_cmpim_old=M[2,6] if regyr==`z'

qui replace low95_young=M[5,1] if regyr==`z'
qui replace high95_young=M[6,1] if regyr==`z'
qui replace low95_old=M[5,2] if regyr==`z'
qui replace high95_old=M[6,2] if regyr==`z'
qui replace low95_minority=M[5,4] if regyr==`z'
qui replace high95_minority=M[6,4] if regyr==`z'
qui replace low95_cmpim_young=M[5,5] if regyr==`z'
qui replace high95_cmpim_young=M[6,5] if regyr==`z'
qui replace low95_cmpim_old=M[5,6] if regyr==`z'
qui replace high95_cmpim_old=M[6,6] if regyr==`z'

qui replace b_young=0 if regyr==1990
qui replace b_old=0 if regyr==1990
qui replace b_minority=0 if regyr==1990
qui replace b_cmpim_young=0 if regyr==1990
qui replace b_cmpim_old=0 if regyr==1990

qui replace se_young=0 if regyr==1990
qui replace se_old=0 if regyr==1990
qui replace se_minority=0 if regyr==1990
qui replace se_cmpim_young=0 if regyr==1990
qui replace se_cmpim_old=0 if regyr==1990

qui replace low95_young=0 if regyr==1990
qui replace high95_young=0 if regyr==1990
qui replace low95_old=0 if regyr==1990
qui replace high95_old=0 if regyr==1990
qui replace low95_minority=0 if regyr==1990
qui replace high95_minority=0 if regyr==1990
qui replace low95_cmpim_young=0 if regyr==1990
qui replace high95_cmpim_young=0 if regyr==1990
qui replace low95_cmpim_old=0 if regyr==1990
qui replace high95_cmpim_old=0 if regyr==1990

}
by regyr, sort: gen byte counter=(_n==1)
keep if counter==1
qui gen maxi=high95_young
qui replace maxi=low95_young if low95_young>maxi
qui replace maxi=high95_old if high95_old>maxi
qui replace maxi=low95_old if low95_old>maxi
qui replace maxi=high95_minority if high95_minority>maxi
qui replace maxi=low95_minority if low95_minority>maxi
qui replace maxi=high95_cmpim_young if high95_cmpim_young>maxi
qui replace maxi=low95_cmpim_young if low95_cmpim_young>maxi
qui replace maxi=high95_cmpim_old if high95_cmpim_old>maxi
qui replace maxi=low95_cmpim_old if low95_cmpim_old>maxi
qui egen maxval=max(maxi)

qui gen mini=high95_young
qui replace mini=low95_young if low95_young<mini
qui replace mini=high95_old if high95_old<mini
qui replace mini=low95_old if low95_old<mini
qui replace mini=high95_minority if high95_minority<mini
qui replace mini=low95_minority if low95_minority<mini
qui replace mini=high95_cmpim_young if high95_cmpim_young<mini
qui replace mini=low95_cmpim_young if low95_cmpim_young<mini
qui replace mini=high95_cmpim_old if high95_cmpim_old<mini
qui replace mini=low95_cmpim_old if low95_cmpim_old<mini
qui egen minval=min(mini)

local max_scale=maxval
local min_scale=minval
local range = (maxval - minval)
local pad = 0.10*(`range')
local min_scale = round(minval - `pad', 1000)
local max_scale = round(maxval + `pad', 1000)
local int_scale=round(((`max_scale' - `min_scale')/5), 5000)
local max_scale = max(round(maxval + `pad', 1000),1000,(`min_scale'+(`int_scale'*5)))

twoway rcap low95_young high95_young regyr, title(`Y', ring(12)) ytitle(Regression coefficients (dollars), margin(small)) xtitle(Year) xlabel(1990 "1990 5pct" 2000 "2000 5pct" 2009 "2005-2009" 2014 "2010-2014" 2019 "2015-2019", labsize(small) nogrid) xmlabel(1990 "15-22 y.o." 2000 "25-32 y.o." 2009 "30-41 y.o." 2014 "35-46 y.o." 2019 "40-51 y.o.", labsize(vsmall) labgap(4)) msize(large) graphregion(margin(l+2 r+5)) graphregion(color(white)) bgcolor(white) yscale(range(`min_scale' `max_scale')) ylabel(`min_scale'(`int_scale')`max_scale', nogrid format(%9.0fc) labsize(vsmall)) yscale(titlegap(*5)) lcolor(green) legend(rows(3) order(2 "young AHA" 4 "older AHA" 6 "US native minorities" 8 "young non-Vietnamese immig." 10 "older non-Vietnamese immig.") size(vsmall) position(6) ring(3)) note("ages of young AHA group in each time period are included in text below x-axis") || scatter b_young regyr, connect(l) lpattern(dash) mcolor(green) lcolor(green) msize(medlarge) yline(0, lwidth(large) lcolor(dkgreen) lpattern(solid)) msymbol(diamond) || rcap low95_old high95_old regyr, msize(large) lcolor(midblue) || scatter b_old regyr, connect(l) lpattern(shortdash) mcolor(midblue) lcolor(midblue) msize(medlarge) msymbol(circle) || rcap low95_minority high95_minority regyr, lcolor(black) || scatter b_minority regyr, connect(l) lpattern(longdash_dot) mcolor(black) lcolor(black) msize(medlarge) msymbol(triangle) || rcap low95_cmpim_young high95_cmpim_young regyr, lcolor(dkorange) || scatter b_cmpim_young regyr, connect(l) lpattern(dash_dot) mcolor(dkorange) lcolor(dkorange) msize(medlarge) msymbol(smdiamond) || rcap low95_cmpim_old high95_cmpim_old regyr, lcolor(red) || scatter b_cmpim_old regyr, connect(l) lpattern(shortdash_dot) mcolor(red) lcolor(red) msize(medlarge) msymbol(smtriangle)
graph export ./output/app_figure4_`Y'.pdf, replace

restore
}

******************************************************************************************
**Appendix Table 1: Comparison of young and older AHA immigrants in 1990 Census

use age incwage yrseduc linincwg ewell HSup colup incwfct perwt ct regyr compgrp lininct inctot gender statefip strata superstrat cluster emp unemp ninlf marst marcolsp marnonanc marnatsp ownershp linvalueh valueh linrentg maxpuma pcap_vpu young metarea ageimm col linfinct linfinct_noaha linincwf incwfct famsize gqhh hhhlHS hhhHS hhhcol hhhewell hhhemp momhh dadhh sibhh hhnat f_natvvet hhad30up msapop clusite linmfinct linmincwg linmvalh linmincwf msaincwfct colov21 calif mvimr ct m_age f_age denompuma using ./temp/CoreData.dta, clear

preserve

putexcel set ./output/app_table1.xls, modify
putexcel B1 = "Young AHA"
putexcel C1 = "Older AHA"
putexcel D1 = "p-value"

local variables "ewell yrseduc emp unemp ninlf linfinct_noaha linvalueh linincwf incwfct famsize gqhh hhhlHS hhhHS hhhcol hhhewell hhhemp momhh dadhh sibhh hhnat f_natvvet hhad30up msapop clusite linmfinct linmincwg linmvalh linmincwf msaincwfct colov21 calif mvimr maxpuma"

local row = 2

local i = 1
foreach var of local variables {
qui svy, subpop(if regyr==1990 & inlist(compgrp, 0, 1)): mean `var',  over(compgrp)
qui matlist r(table)
qui matrix results=r(table)
qui lincom _b[c.`var'@0.compgrp] - _b[c.`var'@1.compgrp]
qui scalar pval=r(p)
    
    local byoung = _b[c.`var'@0.compgrp]
    local bold = _b[c.`var'@1.compgrp]
    local pvalue = pval

    putexcel A`row' = "`var'"
    putexcel B`row' = `byoung'
    putexcel C`row' = `bold'
    putexcel D`row' = `pvalue'
    
    local i = `i' + 1
    local row = `row' + 1
}

putexcel (B2:C2) (B4:C6)  (B10:C10) (B12:C23) (B25:C25) (B30:C34), nformat(percent_d2) overwritefmt

putexcel (B3:C3) (B11:C11), nformat(#.00) overwritefmt

putexcel (B24:C24), nformat(number_sep) overwritefmt

putexcel (B7:C9) (B26:C29), nformat(accountcur) overwritefmt

keep if regyr==1990 & inlist(compgrp, 0, 1)
sort compgrp
by compgrp: sum m_age
by compgrp: sum f_age

******************************************************************************************
**Appendix Table 2: Descriptive values on key economic variables

restore
drop m_age f_age

preserve

keep if inlist(compgrp, 0, 1, 3, 4, 5)

qui collapse (mean) incwage yrseduc linincwg ewell HSup colup incwfct [fw=perwt], by(regyr compgrp) fast

qui order regyr compgrp ewell yrseduc HSup colup linincwg incwage incwfct

save ./temp/app_table2pt1, replace

restore
preserve
keep if inlist(compgrp, 3, 4)
qui replace compgrp=2
qui collapse (mean) incwage yrseduc linincwg ewell HSup colup incwfct [fw=perwt], by(regyr compgrp) fast

append using ./temp/app_table2pt1
sort compgrp regyr

export excel using ./output/app_table2.xlsx, firstrow(variables) replace
erase ./temp/app_table2pt1.dta

restore

******************************************************************************************
**Appendix Table 3: Observation counts and representative populations for Figures 2-5

preserve
keep ewell yrseduc HSup colup linincwg lininct incwage inctot perwt compgrp regyr

local vars ewell yrseduc HSup colup linincwg lininct incwage inctot 

tempfile results
save `results', emptyok

foreach var of local vars {
    qui gen valid = !missing(`var')
    
    qui collapse (count) obs = valid (sum) pop = perwt if valid, by(compgrp regyr)
    
    qui gen variable = "`var'"
    
    qui reshape wide obs pop, i(compgrp variable) j(regyr)
    
    qui append using `results'
    qui save `results', replace
}

use `results', clear

ssc inst missings
missings dropobs variable, force 

qui replace obs1990 = . if inlist(variable, "incwage", "inctot", "lininct", "linincwg", "HSup", "colup")
qui replace pop1990 = . if inlist(variable, "incwage", "inctot", "lininct", "linincwg", "HSup", "colup")

export excel using ./output/app_table3.xlsx, replace cell(A2)

putexcel set ./output/app_table3.xlsx, modify
putexcel A1= "Comparison Group"
putexcel B1 = "Variable"
ds compgrp variable, not
local allvars `r(varlist)'
local colvars
foreach v of local allvars {
    if inlist(substr("`v'",1,3),"obs","pop") {
        local colvars "`colvars' `v'"
    }
}
local c = 3
foreach v of local colvars {
    local colLetter = char(64 + `c')
    putexcel `colLetter'1 = "`v'"
    local c = `c' + 1
}

restore


******************************************************************************************
**Appendix Table 4a: Coefficients for Figures 2 and 4

eststo clear
preserve

keep ewell yrseduc HSup colup linincwg incwage lininct inctot compgrp age gender regyr statefip cluster
keep if inlist(compgrp, 0, 1, 3, 4)
qui replace compgrp=2 if compgrp==3 | compgrp==4
drop if regyr==.

foreach Y in ewell yrseduc {

foreach z of num 1990 2000 2009 2014 2019 {
eststo `Y'_`z': qui areg `Y' ib2.compgrp age gender if regyr==`z', absorb(statefip) vce(cluster statefip) allbaselevels
}
}

foreach Y in HSup colup linincwg incwage lininct inctot {

foreach z of num 2000 2009 2014 2019 {
eststo `Y'_`z': qui areg `Y' ib2.compgrp age gender if regyr==`z', absorb(statefip) vce(cluster statefip) allbaselevels
}
}

esttab using ./output/app_table4a.csv, se nogaps nostar noobs drop(2.compgrp age gender _cons) mtitles title("Coefficients for Figures 2 and 4") replace

restore


******************************************************************************************
**Appendix Table 4b: Coefficients for Figures 3 and 5

eststo clear

keep ewell yrseduc HSup colup linincwg incwage lininct inctot compgrp age gender regyr statefip cluster
keep if inlist(compgrp, 0, 1, 3, 4, 5)
drop if regyr==.

foreach Y in ewell yrseduc {

foreach z of num 1990 2000 2009 2014 2019 {
eststo `Y'_`z': qui areg `Y' ib3.compgrp age gender if regyr==`z', absorb(statefip) vce(cluster statefip) allbaselevels
 }
 }

foreach Y in HSup colup linincwg incwage lininct inctot {

foreach z of num 2000 2009 2014 2019 {
eststo `Y'_`z': qui areg `Y' ib3.compgrp age gender if regyr==`z', absorb(statefip) vce(cluster statefip) allbaselevels
 }
 }
 
esttab using ./output/app_table4b.csv, se nogaps nostar noobs drop(3.compgrp age gender _cons) mtitles title("Coefficients for Figures 3 and 5") replace


******************************************************************************************
**Appendix Table 5: Extensions on Table 1's outcomes using the 2015-2019 American Community Survey

**Base Controls**

eststo clear

use ewell yrseduc HSup colup emp unemp ninlf lininct inctot linincwg incwage marst marcolsp marnonanc marnatsp ownershp linvalueh valueh linrentg maxpuma pcap_vpu young age gender cluster statefip metarea regyr ageimm compgrp col perwt ct if regyr==2019 & inlist(compgrp, 0, 1) using ./temp/CoreData.dta, clear

preserve

foreach Y in ewell yrseduc HSup colup emp unemp ninlf lininct inctot linincwg incwage marst marcolsp marnonanc marnatsp ownershp linvalueh valueh linrentg maxpuma pcap_vpu {
eststo: qui areg `Y' young age gender, absorb(statefip) vce(cluster statefip)
}

esttab _all using ./output/app_table5_wbasecontrols.csv, keep(young) cells(b(star fmt(3)) se(par)) par stats(N r2_a) starlevels(+ 0.10 ++ 0.05 +++ .01) nogap title(Comparison of young versus older AHA immigrants in 2015-2019) replace 


**Extension with Controls for Education and Fluency**

eststo clear

foreach Y in emp unemp ninlf lininct inctot linincwg incwage marst marcolsp marnonanc marnatsp ownershp linvalueh valueh linrentg maxpuma pcap_vpu {
eststo: qui areg `Y' young age gender ewell HSup col, absorb(statefip) vce(cluster statefip)
}

esttab _all using ./output/app_table5_wcontrolsforeducandfluenc.csv, keep(young) cells(b(star fmt(3)) se(par)) par stats(N r2_a) starlevels(+ 0.10 ++ 0.05 +++ .01) nogap title(Comparison of young versus older AHA immigrants in 2015-2019 with extended controls) replace 

**Mean Values**

qui collapse (mean) ewell yrseduc HSup colup emp unemp ninlf lininct inctot linincwg incwage marst marcolsp marnonanc marnatsp ownershp linvalueh valueh linrentg maxpuma pcap_vpu, by(compgrp) fast

qui order ewell yrseduc HSup colup emp unemp ninlf lininct inctot linincwg incwage marst marcolsp marnonanc marnatsp ownershp linvalueh valueh linrentg maxpuma pcap_vpu

qui sort compgrp

qui xpose, clear varname

qui order _varname v1 v2
qui rename v1 youngAHA
qui rename v2 olderAHA

export excel using ./output/app_table5_meanvalues.xls, firstrow(variables) replace

**modify formatting
putexcel set ./output/app_table5_meanvalues.xls, modify

putexcel (B2:C2) (B4:C8) (B13:C17) (B21:C22), nformat(percent_d2) overwritefmt

putexcel (B3:C3), nformat(#.00) overwritefmt

putexcel (B10:C10) (B12:C12) (B19:C19), nformat(number_sep) overwritefmt

putexcel (B9:C9) (B11:C11) (B18:C18) (B20:C20), nformat(accountcur) overwritefmt


******************************************************************************************
**Appendix Table 6: Additional specifications with 2015-2019 American Community Survey

***Column 1: Extension using MSA FE and standard errors clustered by MSA instead of state FE and standard errors clustered by state

eststo clear

restore

foreach Y in ewell yrseduc HSup colup emp unemp ninlf lininct inctot linincwg incwage marst marcolsp marnonanc marnatsp ownershp linvalueh valueh linrentg maxpuma pcap_vpu {
eststo: qui areg `Y' young age gender, absorb(metarea) vce(cluster metarea)
}

esttab _all using ./output/app_table6_col1.csv, keep(young) cells(b(star fmt(3)) se(par)) par starlevels(+ 0.10 ++ 0.05 +++ .01) nogap title(Regressions using MSA FE instead of state FE) replace 
 
 
***Column 2: Extension dropping State FE

eststo clear

foreach Y in ewell yrseduc HSup colup emp unemp ninlf lininct inctot linincwg incwage marst marcolsp marnonanc marnatsp ownershp linvalueh valueh linrentg maxpuma pcap_vpu {
eststo: qui reg `Y' young age gender, vce(cluster statefip)
}

esttab _all using ./output/app_table6_col2.csv, keep(young) cells(b(star fmt(3)) se(par)) par starlevels(+ 0.10 ++ 0.05 +++ .01) nogap title(Regressions without state FE)  replace 


***Column 3: Extension without linear age control

eststo clear

foreach Y in ewell yrseduc HSup colup emp unemp ninlf lininct inctot linincwg incwage marst marcolsp marnonanc marnatsp ownershp linvalueh valueh linrentg maxpuma pcap_vpu {
eststo: qui areg `Y' young gender, absorb(statefip) vce(cluster statefip)
}

esttab _all using ./output/app_table6_col3.csv, keep(young) cells(b(star fmt(3)) se(par)) par  starlevels(+ 0.10 ++ 0.05 +++ .01) nogap title(Regressions without linear age control) replace 


***Column 4: Extension with age^2 term added to linear age control

eststo clear

foreach Y in ewell yrseduc HSup colup emp unemp ninlf lininct inctot linincwg incwage marst marcolsp marnonanc marnatsp ownershp linvalueh valueh linrentg maxpuma pcap_vpu {
eststo: qui areg `Y' young age c.age#c.age gender, absorb(statefip) vce(cluster statefip)
}

esttab _all using ./output/app_table6_col4.csv, keep(young) cells(b(star fmt(3)) se(par)) par  starlevels(+ 0.10 ++ 0.05 +++ .01) nogap title(Regressions with age^2 term added to the existing linear age control) replace 

**************************************************************************
**Appendix Table 7: Base analysis using disaggregated age at arrival bins compared to immigrants 20-21 years old at arrival

eststo clear

gen aha_bin=.
qui replace aha_bin=0 if ageimm >= 14 & ageimm <= 15 & inlist(compgrp, 0, 1)
qui replace aha_bin=1 if ageimm >= 16 & ageimm <= 17 & inlist(compgrp, 0, 1)
qui replace aha_bin=2 if ageimm >= 18 & ageimm <= 19 & inlist(compgrp, 0, 1)
qui replace aha_bin=3 if ageimm >= 20 & ageimm <= 21 & inlist(compgrp, 0, 1)
qui label define aha_bin 0 "14-15" 1 "16-17" 2  "18-19" 3  "20-21"

foreach Y in ewell yrseduc HSup colup emp unemp ninlf lininct inctot linincwg incwage marst marcolsp marnonanc marnatsp ownershp linvalueh valueh linrentg maxpuma pcap_vpu {    
    eststo: qui areg `Y' ib3.aha_bin age gender, absorb(statefip) vce(cluster statefip)
}

esttab _all using ./output/app_table7.csv, keep(0.aha_bin 1.aha_bin 2.aha_bin) varlab(0.aha_bin "14-15" 1.aha_bin "16-17" 2.aha_bin "18-19") cells(b(star fmt(3)) se(par)) par stats(N r2_a) starlevels(+ 0.10 ++ 0.05 +++ .01) nogap title(Base analysis using disaggregated age at arrival bins compared to immigrants 20-21 years old at arrival) replace 


**************************************************************************
**Appendix Table 8: Appendix Table 7 adding controls for education and fluency

eststo clear

foreach Y in emp unemp ninlf lininct inctot linincwg incwage marst marcolsp marnonanc marnatsp ownershp linvalueh valueh linrentg maxpuma pcap_vpu {
    eststo: qui areg `Y' ib3.aha_bin age gender ewell HSup col, absorb(statefip) vce(cluster statefip)
}

esttab _all using ./output/app_table8.csv, keep(0.aha_bin 1.aha_bin 2.aha_bin) varlab(0.aha_bin "14-15" 1.aha_bin "16-17" 2.aha_bin "18-19") cells(b(star fmt(3)) se(par)) par stats(N r2_a) starlevels(+ 0.10 ++ 0.05 +++ .01) nogap title(Appendix Table 7 adding controls for education and fluency) replace 


**************************************************************************
*** End of program
log close
